import send_msg from '@feidao/service/send-msg';

export interface ICountParam {
	criteria: object;
	query_mode: 1;
	sort: {};
	spaceid: string;
	// sql: string;
	systemid: string;
	tablename: string;
}

interface ICountResult {
	query_mode: 1;
	spaceid: string;
	systemid: string;
	tablename: string;
	count: number;
}

export default function del(action_id: string, session_id: string, spaceid: string, systemid: string) {
	const argjson = [] as IArgJsonDelete[];

	function prepare<T extends IBaseTable>(tname: string, data: T[]) {
		argjson.push(...data.map((it) => {
			return {
				criteria: it,
				opflag: 2,
				tname
			};
		}));
	}

	async function exec() {
		const msg = {
			argjson,
			spaceid,
			systemid
		};
		return send_msg(action_id, session_id, spaceid)('dbacc.save.intranet', msg) as Promise<{ code: number; result: any; }>;
	}

	return {
		exec,
		prepare
	};
}
